import java.awt.Color;
import se.lth.cs.ptdc.images.ImageFilter;

public class GaussFilter extends ImageFilter{

	
	public GaussFilter(String name) {
		super(name);
	}
	
	// filtrera bilden i matrisen inPixels och returnera resultatet i
	//	en ny matris. Utnyttja eventuellt värdet av parameter 
	public Color[][] apply(Color[][] inPixels, double paramValue) {
		int height = inPixels.length;
		int width = inPixels[0].length;
		Color[][] outPixels = new Color[height][width];

		short[][] kernel = { {0, 1, 0},
							 { 1, (short)paramValue, 1},
							 { 0, 1, 0} };
		
		short[][] red = new short[height][width]; 
		short[][] green = new short[height][width]; 
		short[][] blue = new short[height][width]; 
		

		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				red[i][j] = (short)inPixels[i][j].getRed();
				green[i][j] = (short)inPixels[i][j].getGreen();
				blue[i][j] = (short)inPixels[i][j].getBlue();
			}
		}
		
		for (int i = 0; i < height; ++i) {
			for (int j = 0; j < width; ++j) {

				if(i > 0 && i < height - 1 && j > 0 && j < width -1) {
					short newRed = convolve(red, i, j, kernel, 4+(int)paramValue);
					short newGreen = convolve(green, i, j, kernel, 4+(int)paramValue);
					short newBlue = convolve(blue, i, j, kernel, 4+(int)paramValue);
					
					outPixels[i][j] = new Color(newRed, newGreen, newBlue);
				} else {
					outPixels[i][j] = inPixels[i][j];
				}
				
			}
		}
		return outPixels;
	}
}
